﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HRM.Utilities;

namespace HRM
{
    public partial class frmTime : Form
    {
        public event ShowDock ShowDockEvent;
        private string _frmName = "";

        public string FrmName
        {
            get { return _frmName; }
            set { _frmName = value; }
        }
        DateTime _FromDate;
        public DateTime FromDate
        {
            get { return _FromDate; }
            set { _FromDate = value; }
        }
        DateTime _ToDate;
        public DateTime ToDate
        {
            get { return _ToDate; }
            set { _ToDate = value; }
        }
        int _tmpNo = 0;
        DialogResult _dlgResult;
        public frmTime(int tmpNo)
        {
            InitializeComponent();
            _dlgResult = DialogResult.Cancel;
            this.KeyPreview = true;
            _tmpNo = tmpNo;
            if (_tmpNo == 1)//dd-MM-yyyy
            {
                DateTextBox dtbFrom = new DateTextBox(txtFromDate);
                DateTextBox dtbTo = new DateTextBox(txtToDate);
                txtFromShort.Visible = false;
                txtToShort.Visible = false;
                txtFromDate.Visible = true;
                txtToDate.Visible = true;
                txtFromDate.Focus();
            }
            else//MM-yyyy
            {
                
                txtFromShort.Visible = true;
                txtToShort.Visible = true;
                txtFromDate.Visible = false;
                txtToDate.Visible = false;
                DateTextBoxShort txtFrom = new DateTextBoxShort(txtFromShort);
                DateTextBoxShort txtTo = new DateTextBoxShort(txtToShort);
                fromDate.Text = "Từ tháng:";
                toDate.Text = "Đến tháng:";
                txtFromShort.Focus();
            }
            
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (_tmpNo == 1)
            {
                _FromDate = UISetting.GetDate(txtFromDate.Text);
                _ToDate = UISetting.GetDate(txtToDate.Text);
            }
            else
            {
                _FromDate = UISetting.GetDate(txtFromShort.Text);
                _ToDate = UISetting.GetDate(txtToShort.Text);
            }
            //if (_ViewDate == DateTime.MinValue)
            //{
            //    MessageBox.Show("Nhập sai ngày tháng", UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    return;
            //}
            _dlgResult = DialogResult.OK;
            this.Close();
        }

        private void frmTime_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.DialogResult = _dlgResult;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            _dlgResult = DialogResult.Cancel;
            this.Close();
        }

        private void frmTime_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    if (!e.Alt && !e.Control)
                    {
                        this.ProcessTabKey(!e.Shift);
                        e.Handled = true;
                    }
                    break;
                case Keys.Escape:
                    this.Close();
                    break;
            }
        }
    }
}
